<!DOCTYPE html>
<html lang="en">

	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<!-- STYLESHEETS -->
		<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
		<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
		<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
		<link rel="stylesheet" type="text/css" href="../../css/responsive.css">

		<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
		<!-- file-input -->
		<link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
		<!-- SELECT2 -->
		<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
		<!-- UNIFORM -->
		<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
		<!-- datatable -->
		<link rel="stylesheet" href="../../js/datatables/datatable.css">
		<!-- WIZARD -->
		<link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css" />
		  <link rel="stylesheet" href="../../js/datepicker/datepicker.css">
		<!-- FONTS
	<link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
-->
	
	</head>

	<body>
		<header class="navbar clearfix" id="header">
		</header>
		<!-- PAGE -->
		<section id="page">
			<!-- SIDEBAR -->
			<div id="sidebar" class="sidebar">
				<div class="sidebar-menu nav-collapse">
					<!-- SIDEBAR MENU -->
					<ul>

					</ul>
					<!-- /SIDEBAR MENU -->
				</div>
			</div>
			<!-- /SIDEBAR -->
			<div id="main-content">
				<div class="container">
					<div class="row">
						<div id="content" class="col-lg-12">
							<!-- PAGE HEADER-->
							<div class="row">
								<div class="col-sm-12">
									<div class="page-header">
										<!-- STYLER -->

										<!-- /STYLER -->
										<!-- BREADCRUMBS -->
										<ul class="breadcrumb">
											<li>
												<i class="fa fa-home"></i>
												<a href="index.html">首页</a>
											</li>
											<li>
												<a href="#">供应商管理</a>
											</li>
											<li>新建供应商</li>
										</ul>
										<!-- /BREADCRUMBS -->

									</div>
								</div>
							</div>
							<!-- /PAGE HEADER -->
							<!-- SAMPLE -->
							<form id="form_coupon">
								<div class="row col-md-12">
									<div class="col-md-3" style="width: 25%;margin:20px 0;">
										<div class="" style="text-align: center;font-size:24px;">基本信息</div>
									</div>
									<div class="col-md-9">
										<div class="box border primary">
										<div class="form-group mrg-bt10-right" style="margin:20px 0;height: 40px;">
												<label class="control-label col-md-3"><span class="required">*</span>供应商编号：</label>
												<div class="col-md-8 inline">
													<input type="text" class="form-control width-50" name="supplierNo"   placeholder="请输入供应商名称" maxlength="50" />
													<input type="hidden" name="id" />
													<span class="error-span"></span>
													<br/><span class="required">必须与旺店通系统供应商编号一致</span>
												</div>
											</div>
											<div class="form-group mrg-bt10-right" style="margin:20px 0;">
												<label class="control-label col-md-3"><span class="required">*</span>供应商名称：</label>
												<div class="col-md-8 inline">
													<input type="text" class="form-control width-50" name="supplierName"   placeholder="请输入供应商名称" maxlength="50" />
													<input type="hidden" name="id" />
													<span class="error-span"></span>
												</div>
											</div>
										</div>
									</div>
								</div>
								<div class="row col-md-12">
									<div class="col-md-3" style="width: 25%;">
										<div class="" style="text-align: center;margin-top:45%;font-size:24px;">联系方式</div>
									</div>
									<div class="col-md-9">
										<div class="box border primary">
											<div class="form-group mrg-bt10-right" style="margin:20px 0;">
												<label class="control-label col-md-3">联系人：</label>
												<div class="col-md-8 inline">
													<input type="text" class="form-control width-50" name="contacts"   placeholder="请输入名字" maxlength="50" />
													<input type="hidden" name="id" />
													<span class="error-span"></span>
												</div>
											</div>
											<div class="form-group mrg-bt10-right" style="margin:20px 0;">
												<label class="control-label col-md-3">电话：</label>
												<div class="col-md-8 inline">
													<input type="text" class="form-control width-50" name="mobile"   placeholder="请输入电话" maxlength="50" />
													<input type="hidden" name="id" />
													<span class="error-span"></span>
												</div>
											</div>
											<div class="form-group mrg-bt10-right" style="margin:20px 0;">
												<label class="control-label col-md-3">地址：</label>
												<div class="col-md-8 inline">
													<input type="text" class="form-control width-50" name="address"   placeholder="请输入地址" maxlength="50" />
													<input type="hidden" name="id" />
													<span class="error-span"></span>
												</div>
											</div>
											<div class="form-group mrg-bt10-right" style="margin:20px 0;">
												<label class="control-label col-md-3">传真：</label>
												<div class="col-md-8 inline">
													<input type="text" class="form-control width-50" name="fax"   placeholder="请输入传真" maxlength="50" />
													<input type="hidden" name="id" />
													<span class="error-span"></span>
												</div>
											</div>
										</div>
									</div>
								</div>
								<div class="row col-md-12">
									<div class="col-md-3" style="width: 25%;">
										<div class="" style="text-align: center;margin-top:45%;font-size:24px;">汇款信息</div>
									</div>
									<div class="col-md-9">
										<div class="box border primary">
											
											<div class="form-group mrg-bt10-right" style="margin:20px 0;">
												<label class="control-label col-md-3"><span class="required">*</span>户名：</label>
												<div class="col-md-8 inline">
													<input type="text" class="form-control width-50" name="accountName"   placeholder="请输入户名" maxlength="50" />
													<input type="hidden" name="id" />
													<span class="error-span"></span>
												</div>
											</div>
											<div class="form-group mrg-bt10-right" style="margin:20px 0;">
												<label class="control-label col-md-3"><span class="required">*</span>账号：</label>
												<div class="col-md-8 inline">
													<input type="text" class="form-control width-50" name="account"   placeholder="请输入账号" maxlength="50" />
													<input type="hidden" name="id" />
													<span class="error-span"></span>
												</div>
											</div>
											<div class="form-group mrg-bt10-right" style="margin:20px 0;">
												<label class="control-label col-md-3"><span class="required">*</span>省/市：</label>
												<div class="col-md-8 inline">
													<div class="col-sm-3" style="padding-left:0;">
														<input type="text" class="form-control" name="province"   placeholder="请输入省" maxlength="50" />
														<input type="hidden" name="id" />
														<span class="error-span"></span>

													</div>
													<div class="col-sm-3" style="padding-left:0;">
														<input type="text" class="form-control" name="city"   placeholder="请输入市" maxlength="50" />
														<input type="hidden" name="id" />
														<span class="error-span"></span>												
													</div>
												
												</div>
											</div>
											<div class="form-group mrg-bt10-right" style="margin:20px 0;">
												<label class="control-label col-md-3"><span class="required">*</span>开户行：</label>
												<div class="col-md-8 inline">
													<input type="text" class="form-control width-50" name="depositBank"   placeholder="请输入开户行" maxlength="50" />
													<input type="hidden" name="id" />
													<span class="error-span"></span>
												</div>
											</div>
											
											<div class="form-group mrg-bt10-right" style="margin:20px 0;">
												<label class="control-label col-md-3"><span class="required">*</span>支行：</label>
												<div class="col-md-8 inline">
													<input type="text" class="form-control width-50" name="receivingBank"   placeholder="请输入收款行" maxlength="50" />
													<input type="hidden" name="id" />
													<span class="error-span"></span>
												</div>
											</div>
											
											
										</div>
									</div>
								</div>
								<div class="row col-md-12 uploadMainImage">
									<div class="col-md-3" style="width: 25%;">
										<div class="" style="text-align: center;margin-top:45%;font-size:24px;">上传图片</div>
									</div>
									<div class="col-md-9" style="line-height:34px;display:inline">
										<div class="box border primary">
											<div style="overflow: hidden;padding:30px 0 0px 17px;">
												<label style="float:left" class="info_txt">
													最多可以上传5张图片，建议尺寸：800*800px，大小不要超过300K。
												</label>
												<div id="upload1" class="addnewimg" style="float:left; margin-left:5px;">
													<span id="fir" class="btn btn-success btn-file">
														<span id="two" class="fileinput-new">上传图片</span>
														<input type="file" upload-file="imageUrlProduct" multiple="" name="uploadFile">
													</span>
												</div>
												<div style="margin-top: 10px;width: 100px" aria-valuemax="100" aria-valuemin="0" role="progressbar" class="progress progress-striped active">
													<div style="width:0%;" class="progress-bar progress-bar-success"></div>
												</div>
											</div>
											<div class="mrg-bt10" style="overflow: hidden;">
												<div id="nestable2">
													<ol class="dd-list" style="display: block;padding-left:20px;overflow: hidden;">
														
													</ol>
												</div>
											</div>
										</div>
									</div>

								</div>
								<div class="row" style="height: 30px;">
									<div class="col-md-12" style="text-align: center;">
										<div class="box">
											<a href="#" class="btn btn-success config bt-submit" style="width: 100px">保存</a>
										</div>
									</div>
							    </div>
							</form>
							<!-- /SAMPLE -->

							<div class="footer-tools">
								<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
							</div>
						</div>
						<!-- /CONTENT-->
					</div>
				</div>
			</div>
		</section>
		<!--/PAGE -->
		<!-- JAVASCRIPTS -->
		<!-- Placed at the end of the document so the pages load faster -->
	    <!-- JQUERY -->
		<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
		<script src="../../js/common.js"></script>
		<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
		<!-- BOOTSTRAP -->
		<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
		<!-- SLIMSCROLL -->
		<script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/jquery.slimscroll.min.js"></script>
		<script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/slimScrollHorizontal.min.js"></script>
		<!-- BLOCK UI -->
		<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
		<!--bootbox-->
		<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
		<!-- AUTOSIZE -->
		<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
		<!-- spinner -->
		<script src="../../js/spinner/spin.js"></script>
		<!-- bootstrap-fileupload -->
		<script type="text/javascript" src="../../js/jquery-upload/js/jquery.iframe-transport.js"></script>
		<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload.min.js"></script>
		<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-process.min.js"></script>
		<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-validate.min.js"></script>
		<!-- INPUT MASK -->
		<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
		<!-- SELECT2 -->
		<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
		<!-- UNIFORM -->
		<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
		<!-- WIZARD -->
		<script src="../../js/bootstrap-wizard/jquery.bootstrap.wizard.min.js"></script>
		<!-- WIZARD -->
		<script src="../../js/jquery-validate/jquery.validate.min.js"></script>
		<script src="../../js/jquery-validate/additional-methods.min.js"></script>
		<script src="../../js/bootstrap-wizard/form-wizard.js"></script>
		<!-- NESTABLE LISTS -->
		<script type="text/javascript" src="../../js/nestable/jquery.nestable.min.js"></script>
		<!-- COOKIE -->
		<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
		<!-- CUSTOM SCRIPT -->
		<script src="../../js/script.js"></script>
		<script src="../../js/Sortable.min.js"></script>
		<script>
			var AddCoupon = function(){
				var id=null,flag;
				var wizform = $('#form_coupon');
				var supplierid=$.getUrlParam('id');//判断是否有id  有id编辑  没id新增
				var flag=$.getUrlParam('flag');
				var img={};


				//初始化验证框架
				var formValiInit=function(){
		        	wizform.validate({
		                doNotHideMessage: true,//不要隐藏信息
						errorClass: 'error-span',
		                errorElement: 'span',
		                rules: {//返回元素的验证规则
		                	supplierNo:{//供应商编号
		                		required:true
		                	},
		                	supplierName:{//供应商名字
		                		required:true
		                	},
							contacts: {//联系人
		                        required: false
		                    },
		                    mobile: {
		                        required: false
		                    },
		                    address:{
		                        required: false
		                    },
		                    fax:{
		                        required: false
		                    },
		                    account:{//账号
		                    	required: true
		                    },
		                    accountName:{//户名
		                    	required: true
		                    },
		                    receivingBank:{//收款行
		                    	required: true
		                    },
		                    depositBank:{//开户行
		                    	required: true
		                    },
		                    province:{//省
		                    	required: true
		                    },
		                    city:{
		                    	required:true
		                    }
		                },
		                highlight: function (element) {
		                    $(element)
		                        .closest('.form-group').removeClass('has-success').addClass('has-error');
		                },
		                unhighlight: function (element) {
		                    $(element)
		                        .closest('.form-group').removeClass('has-error');
		                },
		                success: function (label) {
		                    if(label.attr("for") == "gender") {
		                        label.closest('.form-group').removeClass('has-error').addClass('has-success');
		                        label.remove();
		                    }else{
		                        label.addClass('valid')
		                        .closest('.form-group').removeClass('has-error').addClass('has-success');
		                    }
		                }
					 });
				};

				//新增供应链信息
				var saveSupplier=function(){
					if(wizform.valid() == false)return false;//valid功能函数，回传true/false，是否验证通过
					var p={};
						p.id=supplierid;
						p.supplierNo=$("input[name=supplierNo]").val();
						p.supplierName=$("input[name=supplierName]").val();
						p.contacts=$("input[name=contacts]").val();
						p.mobile=$("input[name=mobile]").val();
						p.address=$("input[name=address]").val();
						p.fax=$("input[name=fax]").val();
						p.account=$("input[name=account]").val();
						p.accountName=$("input[name=accountName]").val();
						p.receivingBank=$("input[name=receivingBank]").val();
						p.depositBank=$("input[name=depositBank]").val();
						p.province=$("input[name=province]").val();
						p.city=$("input[name=city]").val();
						p.area ="";	
						p.imagesPath = [];

					var imgstr = "";
					$("#nestable2").find("img").each(function(index,item){
						imgstr +=$(this).attr("src") +",";	
					});
					p.imagesPath = imgstr;

					if(!p.imagesPath){
						alert('至少请上传一张图片');
						$(".info_txt").css("color","#b94a48");
						return false;
					}
					
					$.ajax({
						type: "post",
						url: App.getContextPath() + "admin/supplier/saveSupplier.do",
						data:$.param({supplier:JSON.stringify(p)}),//参数名字
						async: true,
						success: function(result) {

							if(result.type=="error"){
								$.alert(result.extra);
							}else{

								window.location.href="supply_list.html";
							}
							
						}
					});
				};

				//根据id获取供应链信息
				var getSupplier=function(){
					$.ajax({
						type:"get",
						url:App.getContextPath() + "admin/supplier/getSupplier.do",

						data:{id:supplierid},
						async:true,
						success:function(result){
							setSupplier(result);
						}
					});	
				}


				//编辑供应链信息
				var setSupplier=function(p){
					if(id==null){//如果id为空，则为编辑
						$("input[name=id]").val(p.id);
						$("input[name=supplierNo]").val(p.supplierNo);
						$("input[name=supplierName]").val(p.supplierName);
						$("input[name=contacts").val(p.contacts);
						$("input[name=mobile]").val(p.mobile);
						$("input[name=address]").val(p.address);
						$("input[name=fax]").val(p.fax);
						$("input[name=account]").val(p.account);
						$("input[name=accountName]").val(p.accountName);
						$("input[name=receivingBank]").val(p.receivingBank);
						$("input[name=depositBank]").val(p.depositBank);
						$("input[name=province]").val(p.province);
						$("input[name=city]").val(p.city);
					}
					//如果p.imagesPath不为空，开始渲染图片


					if(p.imagesPath != null){
						//设置商品主图
						var imagesLst=p.imagesPath.split(",");
						for(var i=0;i<imagesLst.length;i++){
							if(imagesLst[i]!=""){
								addMainImageHtml(imagesLst[i],i);//url id	
							}
						}
					} 

				}

				
				//上传商品图片
				var fileUpLoad = function() {
					$(".uploadMainImage").find('.progress-bar').css('width','0%');
					$(".uploadMainImage").find('.progress').hide();
					$("[upload-file=imageUrlProduct]").fileupload({//fileupload 插件方法
						url: App.getContextPath() + "admin/file/uploadImage.do",
						formData: {
							fileType: "ProductDetailImage,ProductListImage,ProductShoppingCartImage"
						},
						dataType: 'json',
						acceptFileTypes: /(\.|\/)(gif|jpe?g|png|JPG?g)$/i,
						iframe: true,
						maxNumberOfFiles: 5,
						autoUpload: true,
						start:function(e) {		    	
					    	$(".uploadMainImage").find('.progress').fadeIn(300);					    	
					    	return true;
				    	},				
						done: function(e, data) {
							var result = data.result;						
					        addMainImageHtml(result.fileUrl,"");
					        $('#nestable2').nestable({maxDepth: 1});
						},						
					    progressall: function (e, data) {					    	
				            var progress = parseInt(data.loaded / data.total * 100, 10);
				           $(".uploadMainImage").find('.progress-bar').css('width',progress + '%');
				        }
					}).on('fileuploaddone',function(e,data) {
							$(".uploadMainImage").find(".progress").fadeOut(300);
					
					});
				};
				


				//添加商品主图
				var addMainImageHtml=function(url,id){
					var i="imgage"+($(".dd-list").find("li").length+1);
					var imgs='<li class="dd-item filter-content" style="float:left;margin-bottom:0;" data-id="'+i+'"><img class="dd-handle" width="180px" height="180px" src="'+url+'" pid="'+id+'"/>'+
						'<div class="hover-content"><a class="btn btn-danger hover-link colorbox-button btn-del-image"  title="删除"><i class="fa fa-times fa-1x"></i></a></div></li>';
					$(".dd-list").append(imgs);
					
					handleHover();
					$(".btn-setMain").unbind("click").bind("click",function(){
					 //已经设置主图的取消设置
					    $(".bt-main").hide();
					    $(this).prev().show();
					    $(this).hide();
					    $(this).next().hide();
					 });
					$(".btn-del-image").click(function(){
					    $(this).closest("li").remove();
					    $("#upload1").show();
					});
					  
					  //如果当前图片个数已经达到5个隐藏上传按钮
					  if($(".dd-list li").length==5)
					  {
					     $("#upload1").hide();
					  }
				};

				//设置主图或者删除
				var handleHover=function(){
					$('.filter-content').hover(function() {
						var hoverContent = $(this).children('.hover-content');
						hoverContent.removeClass('fadeOut').addClass('animated fadeIn').show();

						if(flag=="1"){
							hoverContent.hide();
						}

					}, function(){
						var hoverContent = $(this).children('.hover-content');
						hoverContent.removeClass('fadeIn').addClass('fadeOut').hide();
					});
					
				};

				return {
					init: function() {
						formValiInit();
						App.init();
						$(".bt-submit").click(saveSupplier);
						$('#nestable2').nestable({
							maxDepth: 1
						});
						fileUpLoad();	
						//detailFileUpLoad();
						
						if(supplierid!=null){
							getSupplier();
						}

						//查看状态
						if(flag=="1"){
							$("input").attr("readonly","true");
							$(".btn").hide();
						}
						
					} 
				}
			}();
			$(function() {
				$("#header").load("../head.html");
				AddCoupon.init();
			});

		</script>
		<!-- /JAVASCRIPTS -->
	</body>
</html>